package com.example.algorithm.greedy;

/**
 * @author : zhy
 * @since : 2022/8/30
 * 跳跃游戏二
 */
public class JumpGameTwo {

    public int jump(int[] nums) {

        int maxJump=0;
        int curJump=0;
        int len=nums.length;
        int count=0;
        for(int i=0;i<len;i++)
        {
            maxJump=Math.max(i+nums[i],maxJump);
            if(maxJump>=len-1)
            {
                count++;
                break;
            }
            if(curJump==i)
            {
                curJump=maxJump;
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        JumpGameTwo jumpGameTwo = new JumpGameTwo();
        int []can={2,3,0,1,4};
        System.out.println(jumpGameTwo.jump(can));
    }

}
